package com.badibadi.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.badibadi.infos.Results;
import com.badibadi.infos.discussListModel;
import com.badibadi.infos.personModel;
import com.badibadi.mail.MailFirstSendMailActivity;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.HtmlUtils;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.SinaExpressionTools;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.SinaExpressionActivity;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;
import com.libjph.util.StringUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.view.my_view.My_XListView;
import com.view.my_view.My_XListView.IXListViewListener_1;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.test.UiThreadTest;
import android.text.Editable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

/**
 * 咨询费的评价界面activity_consulting_evaluation_zhuanye
 * 
 * @author Administrator activity_consulting_evaluation_list
 * 
 */
public class ConsultingEvaluationActivity extends BaseActivity implements
		OnClickListener, IXListViewListener_1 {

	private ImageView[] xian;
	private LinearLayout[] changebtn;

	private TextView activity_consulting_evaluation_money,
			activity_consulting_evaluation_pinlunnum,
			activity_consulting_evaluation_name,
			activity_consulting_evaluation_country,
			activity_consulting_evaluation_city,
			activity_consulting_evaluation_qu,
			activity_consulting_evaluation_questionnum,
			activity_consulting_evaluation_answernum,
			activity_consulting_evaluation_zhuanye,
			activity_consulting_evaluation_All_num,
			activity_consulting_evaluation_tiwennum,
			activity_consulting_evaluation_huidanum;
	private My_XListView activity_consulting_evaluation_list;
	private RatingBar activity_consulting_evaluation_xing,
			activity_consulting_evaluation_pinglun_xing;
	private ImageView activity_consulting_evaluation_head,
			activity_consulting_evaluation_pinglun_biaoqing;
	private Button btn_mail, activity_consulting_evaluation_pinglun_send;
	private EditText activity_consulting_evaluation_pinglun_content;
	private CheckBox activity_consulting_evaluation_pinglun_checkbox;
	private ScrollView activity_consulting_evaluation_scrollView1;
	private LinearLayout pinglun_linear;
	private DisplayImageOptions options;

	private String uid;// 需要传入参数质询费评价的人的id（哪一个评价方好友的id）wc(注：如果是进入评论界面，第一：我是问方，进入界面则需传入答方id，第二：我是答方，进入界面则需传入问方id,（统一为对方id）)
	private int Page = 0;
	private Results results, results2, results3;
	private String TType = null, TType_temp = null;
	private personModel personModel;
	private List<discussListModel> discuss_list;
	private Consulting_Comment_Adapter comment_Adapter;
	private String re_uid, zhanneiId, rid, asker_or_answerer, scores,
			is_niming;
	private String chuanru_zhanneiId = null;// 传入的站内信id
	private String chuanru_asker_or_answerer = null;// 传入评论类型
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(ConsultingEvaluationActivity.this);
				try {
					Utils.showMessage(ConsultingEvaluationActivity.this,
							getResources().getString(R.string.l_net_error));
					TType_temp = "";
					activity_consulting_evaluation_list.stopRefresh();
					activity_consulting_evaluation_list.stopLoadMore();
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 2:
				Utils.ExitPrgress(ConsultingEvaluationActivity.this);
				try {
					if (personModel.getDiscussList() != null) {
					} else {
						if (Page > 1) {
							--Page;
						} else {
							Page = 1;
						}
					}
					InitData();
					activity_consulting_evaluation_list.stopRefresh();
					activity_consulting_evaluation_list.stopLoadMore();
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 3:
				Utils.ExitPrgress(ConsultingEvaluationActivity.this);
				try {
					Utils.showMessage(ConsultingEvaluationActivity.this,
							getResources().getString(R.string.l_xa10));
					TType_temp = "";
					activity_consulting_evaluation_list.stopRefresh();
					activity_consulting_evaluation_list.stopLoadMore();
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 4:
				try {
					pinglun_linear.setVisibility(View.VISIBLE);
					activity_consulting_evaluation_pinglun_content.setText("");
					if (uid.equals(Utils
							.getUid(ConsultingEvaluationActivity.this))) {
						re_uid = discuss_list.get(msg.getData().getInt("num"))
								.getUser().getId();
						zhanneiId = discuss_list.get(
								msg.getData().getInt("num"))
								.getZhannei_usercontact_id();
						rid = discuss_list.get(msg.getData().getInt("num"))
								.getId();
						asker_or_answerer = discuss_list.get(
								msg.getData().getInt("num"))
								.getAsker_or_answerer();
//						   
						activity_consulting_evaluation_pinglun_checkbox
								.setVisibility(View.GONE);
					} else {
//						   
						activity_consulting_evaluation_pinglun_checkbox
								.setVisibility(View.VISIBLE);
					}
					activity_consulting_evaluation_pinglun_xing.setRating(0);
					activity_consulting_evaluation_pinglun_checkbox
							.setChecked(true);

					activity_consulting_evaluation_pinglun_content
							.setHint(getResources().getString(R.string.Reply)
									+ "@"
									+ discuss_list
											.get(msg.getData().getInt("num"))
											.getUser().getNickName() + ":");
					activity_consulting_evaluation_pinglun_content
							.setFocusable(true);
					activity_consulting_evaluation_pinglun_content
							.setFocusableInTouchMode(true);
					activity_consulting_evaluation_pinglun_content
							.requestFocus();
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 5:
				Utils.ExitPrgress(ConsultingEvaluationActivity.this);
				Utils.showMessage(ConsultingEvaluationActivity.this,
						getResources().getString(R.string.wx_reply_success));//回复成功
				pinglun_linear.setVisibility(View.GONE);
				Page = 1;
				discuss_list.clear();
				person(TType);
				break;
			case 6:
				Utils.ExitPrgress(ConsultingEvaluationActivity.this);
				Utils.showMessage(ConsultingEvaluationActivity.this,
						getResources().getString(R.string.wx_pinglun_success));//评论成功
				pinglun_linear.setVisibility(View.GONE);
				Page = 1;
				discuss_list.clear();
				person(TType);
				break;
			case 7:
				Utils.ExitPrgress(ConsultingEvaluationActivity.this);
				try {
					Utils.showMessage(ConsultingEvaluationActivity.this,
							getResources().getString(R.string.wx_pinglun_false));//评论失败
					TType_temp = "";
					activity_consulting_evaluation_list.stopRefresh();
					activity_consulting_evaluation_list.stopLoadMore();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 8:
				Utils.ExitPrgress(ConsultingEvaluationActivity.this);
				try {
					Utils.showMessage(ConsultingEvaluationActivity.this,
							getResources().getString(R.string.wx_reply_false));//回复失败
					TType_temp = "";
					activity_consulting_evaluation_list.stopRefresh();
					activity_consulting_evaluation_list.stopLoadMore();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			default:
				break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.activity_consulting_evaluation);
		// try {
		uid = getIntent().getStringExtra("uid");// 需要传入参数质询费评价的人的id（哪一个评价方好友的id）wc(注：如果是进入评论界面，第一：我是问方，进入界面则需传入答方id，第二：我是答方，进入界面则需传入问方id,（统一为对方id）)
		System.out.println("uid"+uid);
		chuanru_zhanneiId = getIntent().getStringExtra("chuanru_zhanneiId");// 传入的站内信id
		chuanru_asker_or_answerer = getIntent().getStringExtra(
				"chuanru_asker_or_answerer");// 评价分类(asker:属于问方评论答方,answerer：属于答方评论问方)
		// } catch (Exception e) {
		// // TODO: handle exception
		// }
//		   
//				+ chuanru_asker_or_answerer);
		Page = 0;
		TType = "1";
		TType_temp = "";
		this.findViewById(R.id.return_btn).setOnClickListener(
				new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						finish();
					}
				});
		init();
	}

	private void init() {
		// TODO Auto-generated method stub
		activity_consulting_evaluation_money = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_money);
		activity_consulting_evaluation_pinlunnum = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_pinlunnum);
		activity_consulting_evaluation_name = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_name);
		activity_consulting_evaluation_country = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_country);
		activity_consulting_evaluation_city = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_city);
		activity_consulting_evaluation_qu = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_qu);
		activity_consulting_evaluation_questionnum = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_questionnum);
		activity_consulting_evaluation_answernum = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_answernum);
		activity_consulting_evaluation_zhuanye = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_zhuanye);
		activity_consulting_evaluation_xing = (RatingBar) this
				.findViewById(R.id.activity_consulting_evaluation_xing);
		activity_consulting_evaluation_scrollView1 = (ScrollView) this
				.findViewById(R.id.activity_consulting_evaluation_scrollView1);
		activity_consulting_evaluation_xing
				.setOnTouchListener(new OnTouchListener() {

					@Override
					public boolean onTouch(View arg0, MotionEvent arg1) {
						// TODO Auto-generated method stub
						return true;
					}
				});
		activity_consulting_evaluation_head = (ImageView) this
				.findViewById(R.id.activity_consulting_evaluation_head);
		activity_consulting_evaluation_All_num = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_All_num);
		activity_consulting_evaluation_tiwennum = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_tiwennum);
		activity_consulting_evaluation_huidanum = (TextView) this
				.findViewById(R.id.activity_consulting_evaluation_huidanum);
		btn_mail = (Button) this.findViewById(R.id.btn_mail);
		activity_consulting_evaluation_pinglun_xing = (RatingBar) this
				.findViewById(R.id.activity_consulting_evaluation_pinglun_xing);
		activity_consulting_evaluation_pinglun_xing.setNumStars(5);
		activity_consulting_evaluation_pinglun_xing
				.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

					@Override
					public void onRatingChanged(RatingBar arg0, float arg1,
							boolean arg2) {
						if (arg1 == 0.5) {
							activity_consulting_evaluation_pinglun_xing
									.setRating(1);
						} else if (arg1 == 1.5) {
							activity_consulting_evaluation_pinglun_xing
									.setRating(2);
						} else if (arg1 == 2.5) {
							activity_consulting_evaluation_pinglun_xing
									.setRating(3);
						} else if (arg1 == 3.5) {
							activity_consulting_evaluation_pinglun_xing
									.setRating(4);
						} else if (arg1 == 4.5) {
							activity_consulting_evaluation_pinglun_xing
									.setRating(5);
						} else {
							activity_consulting_evaluation_pinglun_xing
									.setRating(arg1);
						}
					}
				});
		activity_consulting_evaluation_pinglun_biaoqing = (ImageView) this
				.findViewById(R.id.activity_consulting_evaluation_pinglun_biaoqing);
		activity_consulting_evaluation_pinglun_biaoqing
				.setOnClickListener(this);
		activity_consulting_evaluation_pinglun_send = (Button) this
				.findViewById(R.id.activity_consulting_evaluation_pinglun_send);
		is_niming = "0";
		activity_consulting_evaluation_pinglun_send
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						String content = SinaExpressionTools
								.replaceAllReplaceToPath(activity_consulting_evaluation_pinglun_content
										.getText().toString().trim());
						if (content != null) {
							if (uid.equals(Utils
									.getUid(ConsultingEvaluationActivity.this))) {
								Repaly(Utils
										.getUid(ConsultingEvaluationActivity.this),
										re_uid, zhanneiId, rid,
										asker_or_answerer, content);
							} else {
								// Utils.showMessage(
								// ConsultingEvaluationActivity.this, "评论");
								String score = activity_consulting_evaluation_pinglun_xing
										.getRating() + "";
								ZhanneiToDiscuss(uid, chuanru_zhanneiId, score,
										chuanru_asker_or_answerer, content,
										is_niming);
							}
							// pinglun_linear.setVisibility(View.GONE);
						} else {
							Utils.showMessage(
									ConsultingEvaluationActivity.this,
									getResources().getString(R.string.l_xb57));
						}
					}
				});
		activity_consulting_evaluation_pinglun_content = (EditText) this
				.findViewById(R.id.activity_consulting_evaluation_pinglun_content);
		activity_consulting_evaluation_pinglun_checkbox = (CheckBox) this
				.findViewById(R.id.activity_consulting_evaluation_pinglun_checkbox);

		activity_consulting_evaluation_pinglun_checkbox
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(CompoundButton arg0,
							boolean arg1) {
						// TODO Auto-generated method stub
						if (arg1) {
							is_niming = "1";
						} else {
							is_niming = "0";
						}
					}
				});
		pinglun_linear = (LinearLayout) this.findViewById(R.id.pinglun_linear);
		activity_consulting_evaluation_list = (My_XListView) this
				.findViewById(R.id.activity_consulting_evaluation_list);
		if (uid.equals(Utils.getUid(ConsultingEvaluationActivity.this))) {
			btn_mail.setVisibility(View.GONE);
			pinglun_linear.setVisibility(View.GONE);
			activity_consulting_evaluation_pinglun_xing
					.setVisibility(View.GONE);
			// activity_consulting_evaluation_pinglun_biaoqing
			// .setVisibility(View.GONE);
			activity_consulting_evaluation_pinglun_checkbox
					.setVisibility(View.GONE);
		} else {
			btn_mail.setVisibility(View.VISIBLE);
			pinglun_linear.setVisibility(View.VISIBLE);
			activity_consulting_evaluation_pinglun_xing
					.setVisibility(View.VISIBLE);
			// activity_consulting_evaluation_pinglun_biaoqing
			// .setVisibility(View.VISIBLE);
			activity_consulting_evaluation_pinglun_checkbox
					.setVisibility(View.VISIBLE);
			if (chuanru_zhanneiId != null) {
				pinglun_linear.setVisibility(View.VISIBLE);
				btn_mail.setVisibility(View.GONE);
			} else {
				pinglun_linear.setVisibility(View.GONE);
				btn_mail.setVisibility(View.VISIBLE);
			}
		}

		// pinglun_linear.setVisibility(View.GONE);
		discuss_list = new ArrayList<discussListModel>();
		comment_Adapter = new Consulting_Comment_Adapter();
		activity_consulting_evaluation_list.setXListViewListener(this);
		activity_consulting_evaluation_list.setPullLoadEnable(true);
		activity_consulting_evaluation_list.setPullRefreshEnable(true);
		activity_consulting_evaluation_list.setAdapter(comment_Adapter);
		activity_consulting_evaluation_list.startLoadMore();
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5)).build();
		btn_mail.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(ConsultingEvaluationActivity.this,
						MailFirstSendMailActivity.class);
				intent.putExtra("answer", uid);
				// intent.putExtra(name, value)
				startActivity(intent);
			}
		});

		xian = new ImageView[] { (ImageView) this.findViewById(R.id.xian1),
				(ImageView) this.findViewById(R.id.xian2),
				(ImageView) this.findViewById(R.id.xian3), };
		// 初始化为点击了全部
		xian[0].setSelected(true);
		changebtn = new LinearLayout[] {
				(LinearLayout) this.findViewById(R.id.All),
				(LinearLayout) this.findViewById(R.id.tiwen),
				(LinearLayout) this.findViewById(R.id.answer), };
		for (int i = 0; i < changebtn.length; i++) {
			changebtn[i].setOnClickListener(this);
		}
		// person(TType);
	}

	private void InitData() {
		activity_consulting_evaluation_scrollView1.scrollTo(0, 0);
		activity_consulting_evaluation_money.setText(personModel
				.getAdvisory_fees());
		activity_consulting_evaluation_pinlunnum.setText("("
				+ personModel.getDiscussTotal() + ")");
		activity_consulting_evaluation_name.setText(personModel.getNickName());
		activity_consulting_evaluation_country
				.setText(personModel.getCountry());
		activity_consulting_evaluation_city.setText(personModel.getSheng());
		activity_consulting_evaluation_qu.setText(personModel.getCity());
		activity_consulting_evaluation_questionnum.setText(personModel
				.getAskNum());
		activity_consulting_evaluation_answernum.setText(personModel
				.getAnswerNum());
		if (!StringUtil.isNullOrEmpty(personModel.getSpeciality())) {
			activity_consulting_evaluation_zhuanye.setText(personModel
					.getSpeciality());
		} else {
			activity_consulting_evaluation_zhuanye.setText("无");
		}

		activity_consulting_evaluation_All_num.setText(personModel
				.getDiscussTotal());
		activity_consulting_evaluation_tiwennum.setText(personModel
				.getDiscussAnswer());
		activity_consulting_evaluation_huidanum.setText(personModel
				.getDiscussAsk());
		ImageLoader.getInstance().displayImage(
				Constants.BadiDownImgUrl + personModel.getHead()
						+ Constants.appPhoto4img,
				activity_consulting_evaluation_head, options);
		activity_consulting_evaluation_xing.setNumStars(5);
		String ttt = pand(personModel.getTotalScore());
		if (ttt != null) {
			if (ttt.equals("点")) {
				activity_consulting_evaluation_xing.setRating(Float
						.valueOf(personModel.getTotalScore()));
			} else if (ttt.equals("无点")) {
				activity_consulting_evaluation_xing.setRating(Integer
						.valueOf(personModel.getTotalScore()));
			}
		}
		activity_consulting_evaluation_xing.setFocusable(false);
		activity_consulting_evaluation_xing.setFocusableInTouchMode(false);
		activity_consulting_evaluation_xing.requestFocus();
		if (personModel.getDiscussList() != null) {
			if (TType_temp != null) {
				//    
				discuss_list.clear();
				TType_temp = null;
			} else {
				//    
			}
			discuss_list.addAll(personModel.getDiscussList());
			comment_Adapter.notifyDataSetChanged();
		} else {
			if (TType_temp != null) {
				//    
				discuss_list.clear();
				TType_temp = null;
			} else {
				//    
			}
			comment_Adapter.notifyDataSetChanged();
//			   
		}
		//    
		if (!StringUtil.isNullOrEmpty(personModel.getAsker_or_answerer())) {
			pinglun_linear.setVisibility(View.VISIBLE);
			btn_mail.setVisibility(View.GONE);
			//    
		} else {
			//    
			pinglun_linear.setVisibility(View.GONE);
			if (uid != null
					&& uid.equals(Utils
							.getUid(ConsultingEvaluationActivity.this))) {
				btn_mail.setVisibility(View.GONE);
			} else {
				btn_mail.setVisibility(View.VISIBLE);
			}
		}
		// activity_consulting_evaluation_zhuanye.setText("");
	}

	private String pand(String sd) {
		String dt[] = sd.split("\\.");
		if (dt != null) {
			if (dt.length > 1) {
				return "点";
			} else {
				return "无点";
			}
		} else {
			return null;
		}
	}

	private void person(final String type) {
		// Utils.showPrgress(ConsultingEvaluationActivity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				personModel = new personModel();
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("uid", uid);
				map.put("loginUid",
						Utils.getUid(ConsultingEvaluationActivity.this));
				map.put("type", type);
				map.put("languageType",
						com.badibadi.mytools.Dialog
								.getSystemLanguageType(ConsultingEvaluationActivity.this));
				map.put("page", Page);
				map.put("pageNum", "6");
				if (!StringUtil.isNullOrEmpty(chuanru_zhanneiId)) {
					map.put("zhanneiId", chuanru_zhanneiId);
				}
//				   
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "inner/person");
				if (content != null) {
					results = Utils.checkResult_NNN(getApplicationContext(),
							content);
//					   
					if (results != null && !results.getRetmsg().equals("null")
							&& results.isRet()) {
						try {
							personModel = JSONUtils.getEntityByJsonString(
									results.getRetmsg(), personModel.class);
							System.out.println("pingjia"+results.getRetmsg());
							handler.sendEmptyMessage(2);
						} catch (Exception e) {
							// TODO Auto-generated catch block
							   
						}
					} else {
						if (Page > 1) {
							--Page;
						} else {
							Page = 1;
						}
						handler.sendEmptyMessage(3);
					}
				} else {
					if (Page > 1) {
						--Page;
					} else {
						Page = 1;
					}
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private void Repaly(final String uid, final String re_uid,
			final String zhanneiId, final String rid,
			final String asker_or_answerer, final String content) {
		Utils.showPrgress(ConsultingEvaluationActivity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				// personModel = new personModel();
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("uid", uid);
				map.put("re_uid", re_uid);
				map.put("zhanneiId", zhanneiId);
				map.put("rid", rid);
				map.put("asker_or_answerer", asker_or_answerer);
				map.put("content", content);
				//    
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "inner/repaly");
				if (content != null) {
					results2 = Utils.checkResult_NNN(getApplicationContext(),
							content);
					//    
					// "评价界面回复返回的数据是:" + content + " "
					// + results2.getRetmsg());
					if (results2 != null
							&& !results2.getRetmsg().equals("null")
							&& results2.isRet()) {
						handler.sendEmptyMessage(5);
					} else {
						handler.sendEmptyMessage(8);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private void ZhanneiToDiscuss(final String re_uid, final String zhanneiId,
			final String question_scores, final String asker_or_answerer,
			final String content, final String is_anonymity) {
		Utils.showPrgress(ConsultingEvaluationActivity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				// personModel = new personModel();
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("uid", Utils.getUid(ConsultingEvaluationActivity.this));// 发表评论的人的id
				map.put("re_uid", re_uid);// 被评论的人的id
				map.put("zhanneiId", zhanneiId);// 站内信id
				map.put("question_scores", question_scores);// 评价打分
				map.put("asker_or_answerer", asker_or_answerer);// 评价分类(asker:属于问方评论答方,answerer：属于答方评论问方)
				map.put("content", content);// 评论内容
				map.put("is_anonymity", is_anonymity);// 是否匿名---注意，评论时，问答双方都可以选择匿名
														// 0：否 1：是
				// 注意：两种情况：
				// * 情况一，当为问方评论答方时（问方→答方），后面三个参数一定为：$asker_or_answerer='asker'
				// $uid=问方ID(登录用户ID) $re_uid=答方ID
				// *
				// 情况一，当为答方评论问方时（答方→问方），后面三个参数一定为：$asker_or_answerer='answerer'
				// $uid=答方ID(登录用户ID) $re_uid=问方ID
//				   
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "inner/zhanneiToDiscuss");
				if (content != null) {
					results3 = Utils.checkResult_NNN(getApplicationContext(),
							content);
//					   
//							"评价界面评论返回的数据是:" + content + " "
//									+ results3.getRetmsg());
					if (results3 != null
							&& !results3.getRetmsg().equals("null")
							&& results3.isRet()) {
						handler.sendEmptyMessage(6);
					} else {
						handler.sendEmptyMessage(7);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private class Consulting_Comment_Adapter extends BaseAdapter {
		private DisplayImageOptions options;
		private PopupWindow popup;
		private Message message;
		private Bundle bundle;
		private RelativeLayout tanchuang_huifu, tanchuang_jubao,
				tanchuang_shanchu;

		public Consulting_Comment_Adapter() {
			options = new DisplayImageOptions.Builder()
					.showStubImage(R.drawable.ic_stub)
					.showImageForEmptyUri(R.drawable.noimage)
					.showImageOnFail(R.drawable.noimage).cacheInMemory()
					.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5))
					.build();
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return discuss_list.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return discuss_list.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(final int arg0, View convertView, ViewGroup arg2) {// consulting_item_pinglun_content
			LayoutInflater inflater = LayoutInflater
					.from(ConsultingEvaluationActivity.this);
			convertView = inflater.inflate(R.layout.consulting_item, null);
			ImageView consulting_item_head = (ImageView) convertView
					.findViewById(R.id.consulting_item_head);// 评论人的头像
			TextView consulting_item_name = (TextView) convertView
					.findViewById(R.id.consulting_item_name);// 评论人的名字
			TextView consulting_item_pinglun_content = (TextView) convertView
					.findViewById(R.id.consulting_item_pinglun_content);// 评论的内容
			TextView consulting_item_time = (TextView) convertView
					.findViewById(R.id.consulting_item_time);// 评论的时间
			final ImageView consulting_item_click_huifu = (ImageView) convertView
					.findViewById(R.id.consulting_item_click_huifu);// 回复的
			ImageView consulting_item_head_huifu = (ImageView) convertView
					.findViewById(R.id.consulting_item_head_huifu);
			TextView consulting_item_name_huifu = (TextView) convertView
					.findViewById(R.id.consulting_item_name_huifu);
			TextView consulting_item_pinglun_content_huifu = (TextView) convertView
					.findViewById(R.id.consulting_item_pinglun_content_huifu);
			TextView consulting_item_time_huifu = (TextView) convertView
					.findViewById(R.id.consulting_item_time_huifu);
			LinearLayout linear_huifu = (LinearLayout) convertView
					.findViewById(R.id.linear_huifu);
			LinearLayout consulting_item_click_linear = (LinearLayout) convertView
					.findViewById(R.id.consulting_item_click_linear);
			if (discuss_list.get(arg0).getReply_user() != null
					&& discuss_list.get(arg0).getReply() != null) {
				consulting_item_click_huifu.setVisibility(View.GONE);
				linear_huifu.setVisibility(View.VISIBLE);
				ImageLoader.getInstance().displayImage(
						Constants.BadiDownImgUrl
								+ discuss_list.get(arg0).getReply_user()
										.getHead() + Constants.appPhoto4img,
						consulting_item_head_huifu, options);
				consulting_item_name_huifu.setText(discuss_list.get(arg0)
						.getReply_user().getNickName());
				// consulting_item_pinglun_content_huifu.setText(discuss_list
				// .get(arg0).getReply().getContent());
				new HtmlUtils(ConsultingEvaluationActivity.this,
						consulting_item_pinglun_content_huifu, discuss_list
								.get(arg0).getReply().getContent())
						.showTextView();
				consulting_item_time_huifu.setText(Utils.Get_Data(discuss_list
						.get(arg0).getReply().getTime(), "yyyy-MM-dd HH:mm",
						"000"));
			} else {
				if (uid.equals(Utils.getUid(ConsultingEvaluationActivity.this))) {
					consulting_item_click_huifu.setVisibility(View.VISIBLE);
					consulting_item_click_linear.setVisibility(View.VISIBLE);
				} else {
					consulting_item_click_huifu.setVisibility(View.GONE);
					consulting_item_click_linear.setVisibility(View.GONE);
				}
				linear_huifu.setVisibility(View.GONE);
				consulting_item_click_linear
						.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View arg4) {
								// TODO Auto-generated method stub
//								   
								message = new Message();
								bundle = new Bundle();
								message.what = 4;
								bundle.putInt("num", arg0);
								message.setData(bundle);
								handler.sendMessage(message);
							}
						});
			}
			if (discuss_list.get(arg0).getIs_anonymity() != null
					&& discuss_list.get(arg0).getIs_anonymity().equals("1")) {
				ImageLoader.getInstance().displayImage(
						Constants.BadiDownImgUrl
								+ discuss_list.get(arg0).getAutoHead(),
						consulting_item_head, options);
				consulting_item_name.setText(getResources().getString(
						R.string.wx_Anonymous_user));
			} else {
				ImageLoader.getInstance().displayImage(
						Constants.BadiDownImgUrl
								+ discuss_list.get(arg0).getUser().getHead()
								+ Constants.appPhoto4img, consulting_item_head,
						options);
				consulting_item_name.setText(discuss_list.get(arg0).getUser()
						.getNickName());
			}

			// consulting_item_pinglun_content.setText(discuss_list.get(arg0)
			// .getContent());
			new HtmlUtils(ConsultingEvaluationActivity.this,
					consulting_item_pinglun_content, discuss_list.get(arg0)
							.getContent()).showTextView();

			consulting_item_time.setText(Utils.Get_Data(discuss_list.get(arg0)
					.getTime(), "yyyy-MM-dd HH:mm", "000"));
			return convertView;
		}
	}

	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		// TODO Auto-generated method stub
		if (arg0 == 13 && arg1 == SinaExpressionActivity.ACTIVITY_BIAOQING) {
			if (arg2 != null) {
				String content2 = arg2.getStringExtra("result");
				int index = activity_consulting_evaluation_pinglun_content
						.getSelectionStart();
				Editable edit = activity_consulting_evaluation_pinglun_content
						.getEditableText();
				edit.insert(index, content2);
			}
		}
		super.onActivityResult(arg0, arg1, arg2);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.All:
			TType = "1";
			TType_temp = "";
			person(TType);
			ChangeTo(0);
			break;
		case R.id.tiwen:
			TType = "3";
			TType_temp = "";
			person(TType);
			ChangeTo(1);
			break;
		case R.id.answer:
			TType = "2";
			TType_temp = "";
			person(TType);
			ChangeTo(2);
			break;
		case R.id.activity_consulting_evaluation_pinglun_biaoqing:
			Intent intent1 = new Intent(ConsultingEvaluationActivity.this,
					SinaExpressionActivity.class);
			startActivityForResult(intent1, 13);
			break;
		}
	}

	/**
	 * 线的切换
	 * 
	 * @param i
	 */
	private void ChangeTo(int i) {
		// TODO Auto-generated method stub
		if (xian[i].isSelected() != true && i == 0) {
			xian[0].setSelected(true);
			xian[1].setSelected(false);
			xian[2].setSelected(false);
		} else if (xian[i].isSelected() != true && i == 1) {
			xian[0].setSelected(false);
			xian[1].setSelected(true);
			xian[2].setSelected(false);
		} else if (xian[i].isSelected() != true && i == 2) {
			xian[0].setSelected(false);
			xian[1].setSelected(false);
			xian[2].setSelected(true);
		}
	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		Page = 1;
		discuss_list.clear();
		person(TType);
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		++Page;
		person(TType);
	}

}
